/*按需获取URL上的参数*/
export function getQueryVariable() {
  var query = window.location.pathname.length > 0 ? window.location.pathname.substring(1) : ''
  // console.log(query)
  if (query) {
    return query
  } else {
    return false
  }
}

/*格式化时间*/
export function formarTime(time) {
  // console.log(time);
  var oldTimes = time.split(' ')
  var newTimes = oldTimes[1] + '\n' + oldTimes[0]
  newTimes = newTimes.replace(/:/g, ' : ')
  // console.log(newTimes);
  return newTimes
}

/* 处理excel数据
 * export2Excel(excelTitle, list, name) 导出Excel表
 * excelTitle Arrary=[{},{}]  表头=[{title:'',key:''}]
 * list = [] table的数据 [{},{}]
 */
// import { createRequire } from 'node_modules'
// const require = createRequire(import.meta.url)
export function export2Excel(excelTitle, list, name) {
  require.ensure([], () => {
    const { export_json_to_excel } = require('./Excel/Export2Excel')
    let tHeader = []
    let filterVal = []
    // console.log(columns)
    if (!excelTitle) {
      return
    }
    excelTitle.forEach((item) => {
      tHeader.push(item.title)
      // console.log(tHeader)
      filterVal.push(item.key)
      // console.log(filterVal)
    })
    const data = list.map((v) => filterVal.map((j) => v[j]))
    // console.log(data)
    export_json_to_excel(tHeader, data, name)
  })
}
